package com.kotlin.coroutine.to_use

import com.kotlin.coroutine.to_use.domain.SearchResponseDTO
import com.kotlin.coroutine.config.logger
import com.kotlin.coroutine.to_use.domain.NotSuspendService
import com.kotlin.coroutine.to_use.domain.RunBlockingService
import com.kotlin.coroutine.to_use.domain.SearchService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController

@RestController
@RequestMapping("/api/v1")
class SearchController {

    @Autowired
    private lateinit var searchService: SearchService
    @Autowired
    private lateinit var notSuspendService: NotSuspendService
    @Autowired
    private lateinit var runBlockingService: RunBlockingService

    @GetMapping("/search")
    suspend fun matchQuery(
        @RequestParam("word") word: String
    ): ResponseEntity<SearchResponseDTO>{
        val res = searchService.matchQuery(word)
        val res2 = searchService.matchQuery2(word)


        return ResponseEntity.ok(res)
    }

    @GetMapping("/not")
    fun not(){
        notSuspendService.notSuspend()
    }

    @GetMapping("/runblock")
    fun runblock(){
        runBlockingService.test()
    }

    companion object {
        private val logger = logger<SearchController>()
    }

}